package com.starbaba.masterworker;

import java.util.ArrayList;
import java.util.List;
import java.util.Queue;

@SuppressWarnings("unchecked")
public class Worker implements Runnable {
	//任务队列，用户取得子任务，是线程安全的
	protected Queue<Integer> workQueue;
	//总结果集
	protected List<List<Object>> resultList;
	
	public List<Integer> inputList = new ArrayList<>();
	
	public void setWorkQueue(Queue<Integer> workQueue) {
		this.workQueue = workQueue;
	}



	
	//子任务处理的逻辑，在子类中实现具体逻辑
	public List<?> handle(Integer input){
		return null;
	}


	public void setResultList(List<List<Object>> resultList) {
		this.resultList = resultList;
	}



	@Override
	public void run() { 
		while(true){
			Integer input = workQueue.poll();
			if(input == null){
				break;
			}
			//处理子任务
			List<Object> dataList = (List<Object>) handle(input);
			if(dataList != null && dataList.size() > 0){
//				LogService.info("index is :" + input + " this time is : " + ((RechargeDetailRecordVO)dataList.get(1)).getDate());
				resultList.set(input, dataList);
			}	
		}
	}
}